package org.edu.modules.kwgl.controller;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.system.vo.LoginUser;
import org.edu.modules.kwgl.api.TestSystemApi;
import org.edu.modules.kwgl.api.TestTeachersAndStudentsApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags="第三方接口调用")
@RestController
@RequestMapping("/kwgl")
@Slf4j
public class ThirdApiController {
    @Autowired
    private TestTeachersAndStudentsApi tsApi;
    @Autowired
    private TestSystemApi systemApi;


    String token = "";

    //获取所有校区信息
    @PostMapping("/edu-teach/teach/veKfcTeachStudentclass/list")
    Result<?> queryStudentList(){
        Result<?>  result;
        try{
            result=tsApi.queryStudentList(token);
        }catch(Exception e){
            systemApi();
            result=tsApi.queryStudentList(token);
        }
        return result;
    }


    //登入
    @GetMapping("/edu-teach/teach/veBaseBanji/list")
    Result<?> systemApi(){
        LoginUser user=new LoginUser();
        user.setUsername("admin");
        user.setPassword("123456");
        Result<JSONObject> result=systemApi.sLogin(user);

        token= result.getResult().getString("token");
        log.info(token);
        return Result.OK();
    }



}
